package com.jquest.layer;

import com.jquest.data.Sprite;
import org.newdawn.slick.Graphics;

import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Johan
 * Date: 2009-dec-11
 * Time: 17:23:43
 * To change this template use File | Settings | File Templates.
 */
public class SpriteLayer extends MapLayer {

    private String name;
    private ArrayList<Sprite> sprites;

    public SpriteLayer(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public int getCount() {
        return sprites.size();
    }

    public ArrayList<Sprite> getSprites() {
        return sprites;
    }


    public void add(Sprite sprite) {
        sprites.add(sprite);
    }

    public void remove(Sprite sprite) {
        sprites.remove(sprite);
    }

    public void render(Graphics g) {
        if(isEnabled()) {
            for(Sprite sprite : sprites) {
                g.drawImage(sprite.getImage(), sprite.getX(), sprite.getY());
            }
        }
    }

    public void update(int time) {
        if(isEnabled()) {
            for(Sprite sprite : sprites) {
                sprite.update(time);
            }
        }
    }

}
